<template>
  <div class="monitor_page">
    <div class="monitor_page-filter">
      <el-form ref="form" label-width="100px" :inline="true">
        <el-form-item label="起止时间：">
          <el-date-picker
            style="width:100%;min-width:240px"
            size="small"
            value-format="timestamp"
            v-model="timerArray"
            type="datetimerange"
            :picker-options="pickerOptions"
            :clearable="false"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期">
          </el-date-picker>
        </el-form-item>
      </el-form>
    </div>

    <div class="monitor_page-filter flex-between">
      <div class="monitor_page-filter-left">
        <el-button
          @click="confirmDelete"
          icon="el-icon-delete-solid"
          v-if="isAuthority"
          type="danger">删除
        </el-button>
        <el-button
          type="primary"
          class="common_btn-defalut"
          icon="el-icon-search"
          @click="form.page=1;$emit('update')">搜索
        </el-button>
      </div>
    </div>

    <div style="width: 100%;padding-left: 10px">
      <el-tabs type="border-card" v-model="activeName" @tab-click="clickTab">
        <el-tab-pane label="数据表格" name="1">
          <span slot="label"><i class="el-icon-date"></i> 数据表格</span>
          <!-- table -->
          <el-table
            :data="tableList"
            border
            @selection-change="handleSelectionChange"
            ref="multipleTable"
            tooltip-effect="dark">
            <el-table-column type="selection" width="28">
            </el-table-column>
            <el-table-column prop="createTime" label="数据采集时间" min-width="135">
              <template slot-scope="scope">
                {{scope.row.createTime | formatTimer }}
              </template>
            </el-table-column>
            <el-table-column prop="xg" label="xg(g)" min-width="100">
            </el-table-column>
            <el-table-column prop="yg" label="yg(g)" min-width="100">
            </el-table-column>
            <el-table-column prop="zg" label="zg(g)" min-width="100">
            </el-table-column>
          </el-table>
          <!-- 分页器 -->
          <el-pagination
            :disabled="isToggleStatus"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="form.page"
            :page-size="form.pageSize"
            :page-sizes="[10, 20, 30, 40,50,60,70,80,90,100]"
            layout="sizes, prev, pager, next,jumper"
            :total="form.total">
          </el-pagination>
        </el-tab-pane>

        <el-tab-pane label="数据绘图" name="2">
          <span slot="label"><i class="el-icon-s-marketing"></i> 数据绘图</span>
          <el-card class="card_echarts" shadow="hover">
            <echarts-ten-change ref="echartsTenChange"></echarts-ten-change>
          </el-card>
        </el-tab-pane>
      </el-tabs>
    </div>
    <dialog-remark ref="remark" @update="$emit('update')"></dialog-remark>
    <monitor-remark ref="monitorRemark" @update="$emit('update')"></monitor-remark>

    <el-dialog
      :title="dialogTitle"
      :visible.sync="isShowDialog"
      :before-close="handleClose"
      :close-on-click-modal="false">
      <div style="height: 50vh">
        <echarts-ten-draw @showRemarkDailog1="showRemarkDailog" ref="echartsTenDraw1"></echarts-ten-draw>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import EchartsTenChange from "../monitor-echarts/base/echarts-13-change";
  import EchartsTenDraw from "../monitor-echarts/base/echarts-13-draw";
  import Format from '@/utils/format'

  import ItemMixins from './item.mixins'
  import {getDictData} from '@/services/model/common'

  export default {
    mixins: [ItemMixins],
    components: {EchartsTenChange, EchartsTenDraw},
    props: ["calcType",],
    data() {
      return {
        activeName: "2",
        dialogTitle: "111",
        isShowDialog: false,
        EnumQuakeCalcTypeList: [],
        // 当前的图表钩子
        chartsName: ['echartsTenChange'],
        // 分页参数
        form: {
          page: 1,
          pageSize: 10,
          total: 0,

        },

      }
    },
    computed: {
      calcTypeData: {
        get() {
          return this.calcType;
        },
        set(value) {
          this.$emit("update:calcType", value);
        },
      }
    },
    methods: {
      //tab 切换进行echart随着窗口改变方法，让数据重新渲染，
      clickTab() {
        this.chartsName.map((name) => {
          if (this.$refs[name]) {
            this.$nextTick(() => {
              this.$refs[name].echartResize();
            });
          }
        });

      },
      handleClose() {
        this.isShowDialog = false;
      },
      showRemarkDailog(data, list) {
        this.dialogTitle = Format(new Date(data.data[0]))+'动态采集曲线图'
        this.isShowDialog = true;
        let index = list.recordList.length - 1 - data.dataIndex
        this.$nextTick(() => {

          this.$refs.echartsTenDraw1.updateEchart(list, index)
        })

      },
      // 通用获取枚举方法
      async queryDictData(enumName, model) {
        const {data} = await getDictData({enumName})
        if (model) this[model] = data || []
        return data || []
      },

      update({data, monitorName, monitorInfo}) {
        this.equipId = monitorInfo.bindEquipId
        this.collectionList = data.recordList || []
        this.form.page = 1;
        this.form.total = this.collectionList.length
        this.$nextTick(()=>{
          this.$refs.echartsTenChange.updateEchart(data,monitorName,monitorInfo)

        })
      },
      // 数据刷新
    },
    mounted() {
      this.queryDictData('EnumQuakeCalcType', 'EnumQuakeCalcTypeList')

    }
  }
</script>

<style lang="less" scoped="scoped">
  @import url('./commom.less');

  // 还需自定义的css
  .card_echarts {
    height: 550px;
  }

  .el-card {
    background: transparent;
  }


</style>

